#!/usr/bin/python
# -*- coding: utf-8 -*-
#Python Es la Riata.com
#Fecha: 29/noviembre/2011
#R.A.P.S
import sys, os             
pathname = os.path.dirname(sys.argv[0])        
ruta=pathname.split("/src")
Exacto=os.path.abspath(ruta[0])
try:
	import gtk
	from reproductor import *
except ImportError:
    sys.exit("pygtk not found.")
	
class Loading:
	def __init__(self,parent,xmms):
		self.parent = parent
		self.builder = gtk.Builder()
		UI_FILE=Exacto+"/data/openlist.ui"
		self.builder.add_from_file(UI_FILE)
			
		self.opventana= self.builder.get_object("opventana")
		self.baceptar= self.builder.get_object("oklist")
		self.bquitar = self.builder.get_object("quitarlist")
		self.combobox1= self.builder.get_object("combobox1")

		self.xmms = xmms
		self.xmms.playlist_list(self.NameList)
		
		self.builder.connect_signals(self)

	def NameList(self,result):
		llenacombo(self.combobox1,result.value())

	def Aclist(self, widget, *event):
		loading = valor_combobox(self.combobox1)
		self.xmms.playlist_load(loading)
		if self.parent.pick==True:
			self.parent.app_listilla.ratero.destroy()
			self.parent.listagot(2)
		else:
			self.parent.listagot(2)
		self.parent.gooto("OK",150,160)
	def quitarRolx(self, result):
			Actual=result.value()
			loading = valor_combobox(self.combobox1)
			if Actual==loading:
				self.parent.gooto("No se puede Eliminar la Lista de Reproduccion Actual",400,170)
			else:
				self.xmms.playlist_remove(loading)
				self.opventana.destroy()
				self.parent.Loadlist(1,2)
				self.parent.gooto("Se Elimino correctamente*",300,170)

	def Actuad(self, widget, *event):
		self.xmms.playlist_current_active(self.quitarRolx)
		
#############################LLena Combobox#################################################################

def llenacombo(combo,valor):
		bip=0
		store = gtk.ListStore(int,str)
		for val in valor:
			if val!="_active":
				store.append([bip,val])
				bip=bip+1
		combo.set_model(store)
		cell=gtk.CellRendererText()
		combo.pack_start(cell, True)
		combo.add_attribute(cell, 'text',1)
		combo.set_active(0)

def valor_combobox(combobox):
	model = combobox.get_model()
	activo = combobox.get_active()
	if activo <0:
		return None
	return model[activo][1]
